<?php
	//require_once "common.php";
	class page{
		private $num;//总记录数
		private $page;//总页数
		private $subPage;//单页显示条数
		private $currentPage;//当前页
		private $url;//显示分页的页面地址
		var $pageArray=array();
		function __construct($num,$subPage,$currentPage,$url){
			$this->num=$num;
			$this->subPage=$subPage;
			$this->currentPage=$currentPage;
			$this->url=$url;

		}
		//function __unset(){

		//}
		//function __call(){

		//}
		function initArray(){
			if($this->num%$this->subPage==0){
				$this->page=$this->num/$this->subPage;
			}else{
				$this->page=ceil($this->num/$this->subPage);
				$this->page=(int)$this->page;
			}
			for($i=0;$i<$this->page;$i++){
				$this->pageArray[$i]=$i+1;
			}
			//print_r($this->pageArray);
		}
		function setCurrentPage(){
			if($this->currentPage<1){
				$this->currentPage=1;
			}elseif($this->currentPage>=$this->page){
				$this->currentPage=$this->page;
			}
		}
		function outPut(){
			$this->initArray();
			$this->setCurrentPage();
			$nowPage=$this->currentPage;
			if(--$nowPage<1){
				echo "上一页&nbsp";
			}else{
				echo "<a href=".$this->url."&page=".$nowPage.">上一页</a>&nbsp";
			}
			for($i=0;$i<$this->page;$i++){
				if($i==$this->currentPage-1){
					echo $this->pageArray[$i]."&nbsp";
				}else{
					echo "<a href=".$this->url."&page=".$this->pageArray[$i].">".$this->pageArray[$i]."</a>&nbsp";
				}
			}
			$nowPage=$nowPage+2;
			if($nowPage>$this->page){
				$nowPage=$this->page;
				echo "下一页";
			}else{
				echo "<a href=".$this->url."&page=".$nowPage.">下一页</a>";
			}
		}
}
//调用测试
	//$page=new page(30,5,$_GET[page],"./page.php");
	//$page->outPut();









?>
